<template>
  <div class="search">
    <div class="header">
      <van-sticky>
        <van-search
          left-icon="none"
          shape="round"
          v-model="value"
          show-action
          placeholder="请输入搜索关键词"
        >
          <template #action>
            <div @click="search(value)" class="btn-serch">搜素</div>
          </template>
        </van-search>
      </van-sticky>
      <van-icon @click="ret" name="arrow-left" />
    </div>
    <div class="content">
      <!-- 左边的列表 -->
      <div class="leftbox">
        <div class="left">
          <van-sidebar v-model="activeKey" @change="onChange">
            <van-sidebar-item
              v-for="(item, index) in classifylist"
              :key="index"
              :title="item"
            />
          </van-sidebar>
        </div>
      </div>

      <!-- 右边的商品 -->
      <div class="right">
        <div class="item" v-for="item in searchlist" :key="item.id">
          <div class="item-center">
            <div class="left">
              <img :src="item.src" alt="" />
            </div>
            <div class="right">
              <div class="msg">
                <div class="van-multi-ellipsis--l2">
                  {{ item.goodmsg }}
                </div>
              </div>
              <div class="canshu">单价:￥{{ item.goodprice }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
$main: #c0aa95;
.header {
  .van-search__action {
    height: 30px;
    width: 60px;
    border-radius: 990px;
    border: 1px solid $main;
    background-color: $main;
    color: white;
    margin-left: 5px;
  }
  .van-search__action div {
    line-height: 30px;
    /* color: #c0aa95; */
  }
  .van-search__content {
    border-radius: 99px;
    margin-left: 40px;
  }
  .van-search {
    background-color: #eae9e5;
    text-align: center;
    box-sizing: content-box;
    padding: 20px 10px 10px;
  }
  .van-icon-arrow-left {
    font-size: 20px;
    font-weight: 700;
    color: $main;
    position: fixed;
    left: 15px;
    top: 27px;
    box-sizing: content-box;
  }
}
.content {
  flex: 1;
  // height: ;
  overflow: scroll;
  display: flex;
  .leftbox {
    width: 77px;
    overflow: hidden;
    .left {
      height: 100%;
      overflow-y: scroll;
      position: fixed;
    }
  }

  .right {
    // height: 100vh;
    // width: calc(100vh-120px);
    flex: 1;
    .item {
      padding: 15px 10px;
      .item-center {
        height: 100px;
        // background-color: $main;
        display: flex;
        justify-content: space-around;
        .left {
          width: 100px;
          height: 100%;
          overflow: hidden;
          border-radius: 8px;
          margin-right: 15px;
          img {
            width: 100%;
            height: 100%;
          }
        }
        .right {
          font-size: 14px;
          width: 170px;
          .msg {
            height: 40px;
          }
          .canshu {
            margin-top: 5px;
            padding-left: 5px;
            height: 50px;
            background-color: rgba(248, 248, 248, 1);
            color: #999999;
            text-align: left;
            line-height: 50px;
          }
        }
      }
    }
  }
}
</style>
<script>
import goodsModel from "../model/goodsModel";
export default {
  data() {
    return {
      value: "",
      searchlist: [],
      activeKey: 0,
      classifylist: ["商品", "价格 ↑", "价格 ↓"],
    };
  },
  methods: {
    ret() {
      this.$router.go(-1);
    },
    search(val) {
      goodsModel.query().then((res) => {
        this.searchlist = res.data.filter((item) => {
          return item.goodmsg.indexOf(val) != -1;
        });
        console.log(this.searchlist);
      });
    },

    onChange(index) {
      // Notify({ type: "primary", message: this.classifylist[index] });
      console.log(this.classifylist[index]);
      let classify = this.classifylist[index];
      goodsModel.query({ classify: classify }).then((res) => {
        this.goodslist = res.data;
        console.log(this.goodslist);
        // item1 = this.goodslist.filter;
      });
    },
  },
};
</script>